package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.dao.CategoryDao;
import com.itheima.reggie.dao.DishDao;
import com.itheima.reggie.dao.SetmealDao;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, Category>
                implements ICategoryService {
    @Autowired
    CategoryDao categoryDao;
    @Autowired
    DishDao dishDao;
    @Autowired
    SetmealDao setmealDao;

    @Override
    public Boolean deleteById(Long id){
        LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Dish::getCategoryId,id);

        LambdaQueryWrapper<Setmeal> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(Setmeal::getCategoryId,id);

        Integer count = dishDao.selectCount(queryWrapper);
        Integer count1 = setmealDao.selectCount(queryWrapper1);
        if(count>0 || count1 >0){
            return false;
        }
        int result=categoryDao.deleteById(id);
        return true;
     }
}
